package com.wallace.downloadserver.netty

import com.wallace.downloadserver.netty.handler.inbound.NettyMsgDecryptHandler
import com.wallace.downloadserver.netty.handler.inbound.NettyMsgHandler
import com.wallace.downloadserver.netty.handler.outbound.NettyMsgEncryptHandler
import io.netty.channel.ChannelInitializer
import io.netty.channel.socket.SocketChannel
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

/**
 * @Author: Wallace
 * @Description:
 * @Date: 2022/2/15 21:51
 * @Modified By:
 */
@Component
class ServerChannelInitializer : ChannelInitializer<SocketChannel>() {

    @Autowired
    private var nettyManager: NettyManager? = null

    override fun initChannel(ch: SocketChannel) {
        val pipeline = ch.pipeline()
        // inBound
        pipeline.addLast(NettyMsgDecryptHandler(nettyManager!!))
        // outBound
        pipeline.addLast(NettyMsgEncryptHandler(nettyManager!!))
        // inBound
        pipeline.addLast(NettyMsgHandler())
    }
}